/**
 * <p>向导form，默认拥有“上一步”、“下一步”按钮</p>
 * xtype = cceafguidepanel

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.GuidePanel
 * @extends Ext.panel.Panel
 * @since 1.0
 */
Ext.define('cceaf.control.GuidePanel',{
	extend: 'Ext.panel.Panel', 
    alias: 'widget.cceafguidepanel',
    requires: [
        'cceaf.control.FieldSet'
    ],

	constructor: function(config){
		config = config || {};
        
		cceaf.control.GuidePanel.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * 是否有关闭按钮
	 *
     * @property hasClose 
     * @type Boolean
     * @default true
     */
    hasClose: false,
    
    /**
	 * 向导数
	 *
     * @property stepNumber
     * @type number
     * @default 0
     */
    stepNumber: 0,
    
    /**
	 * 当前的item
	 *
     * @property activeItem
     * @type number
     * @default 0
     */
    activeItem: 0,
    
	initComponent : function(){
		var config = this;
		
		var activeItem = config.activeItem;
		var stepNumber = config.stepNumber;
		
		if (stepNumber <1) {
			alert('请设置正确的向导步数！');
			return;
		}
		if (activeItem <0 || activeItem > stepNumber-1) {
			alert('请设置正确的向导页！');
			return;
		}
		
		var btnPrevDisabled;
		var btnNextDisabled;
		var btnNextText;
		var btnNextIconCls;
		if (stepNumber == 1) {
			btnPrevDisabled = true;
			btnNextDisabled = false;
			btnNextText = " 完成 ";
			btnNextIconCls = "completeIcon";
		} else {//stepNumber>1
			if (activeItem == 0) {
				btnPrevDisabled = true;
				btnNextDisabled = false;
				btnNextText = " 下一步 ";
				btnNextIconCls = "nextIcon";
			} else {
				btnPrevDisabled = false;
				btnNextDisabled = false;
				if (activeItem == stepNumber - 1) {
					btnNextText = " 完成 ";
					btnNextIconCls = "completeIcon";
				} else {
					btnNextText = " 下一步 ";
					btnNextIconCls = "nextIcon";
				}
			}
		}
		
		var operateArea = [], i=0;
		operateArea[i++] = {
			xtype: "tbfill"
		};
		operateArea[i++] = {
			itemId: 'btnPrev', 
			iconCls: 'previousIcon', 
			text: ' 上一步  ', 
			pressed: true,
			disabled: btnPrevDisabled
		};
		operateArea[i++] = {
			itemId: 'btnNext', 
			iconCls: btnNextIconCls, 
			text: btnNextText, 
			pressed: true,
			disabled: btnNextDisabled
		};
		if (config.hasClose) {
			operateArea[i++] = {
				itemId: 'btnClose', 
				iconCls: 'closeIcon', 
				text: ' 关闭  ', 
				pressed: true
			};
		}
		
        Ext.applyIf(this, {
        	title: '向导',
        	layout: 'card',
        	activeItem: 0,
            bodyStyle: 'padding:5px',
            defaults: {
                border: false
            },
            dockedItems: {
            	dock: 'bottom', 
				xtype: 'toolbar',
				items: operateArea
            }
		});
		
		cceaf.control.GuidePanel.superclass.initComponent.call(this);
    }
	
});